<?
require_once (__DIR__ . '/../models/Accounts.php');
require_once (__DIR__ . '/../models/Users.php');
require_once (__DIR__ . '/../models/PaymentMethods.php');
require_once (__DIR__ . '/../models/Keywords.php');

	switch ($_SERVER['REQUEST_METHOD']) {
		case 'POST':
		print_r($_POST);
			
		$row['paymentType'] = keywords::GetId("creditCard");
				
		 
			break;			
		case 'PUT':			
			break;
		case 'DELETE':			
			break;
		case 'GET':
			$user=User();
			$results = paymentMethods::GetForUser($user['id']);
			if($results==false)
			{
				$data=Array('status'=>'failure','reason'=>'empty');
			}
			else 
				{
					while ($row = $results->fetch_assoc())
					{
						$cardtype = keywords::GetName($row['accountType']);
						$lastfour = substr($row['accountNumber'],strlen($row['accountNumber'])-5,4);
						$option[]=Array('value'=>$row['id'],'label'=> $cardtype . ' ending in ' . $lastfour );
					}
					$data=Array('status'=>'success','reason'=>'','option'=>$option);
				}
			echo json_encode($data);
			break;
		default:
			break;	
	}